home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / DIO.H < prev    next >
C/C++ Source or Header  |  1995-05-25  |  9KB  |  354 lines

  1. #ifndef _DIO_H_
  2. #define _DIO_H_
  3. //----------------------------------------------------------------------------
  4. //                            MODULE DESCRIPTION
  5. //
  6. //  Module:    data.h
  7. //   Title:    Data File I/O Library
  8. //  Notice:    John M. Weeder
  9. //                 Copyright (c) 1993. All rights reserved.
  10. //             This module contains proprietary information and should be 
  11. //                treated as confidential.
  12. //
  13. //----------------------------------------------------------------------------
  14. //                           MAINTENANCE HISTORY
  15. //
  16. // $Workfile$
  17. // $Revision$
  18. //   $Author$
  19. //     $Date$
  20. //      $Log$    
  21. //
  22. //----------------------------------------------------------------------------
  23. //                             MODULE NARRATIVE
  24. //
  25. //
  26. //    This module is the primary header file for the data file library.
  27. //
  28. //    Characteristics of data files:
  29. //        All logical files start on a 512 byte boundary.
  30. //        Each file has 32 flag bits. The upper 16 are for internal use. The
  31. //            lower 16 may be user defined.
  32. //        Each physical file has a user data area
  33. //        Each logical file has a user data area
  34. //
  35. //    The code in this module should be written entirely in C. 
  36. //    Do not use any C++ constructs.
  37. //
  38. //    This module is portable to:
  39. //        DOS 3.X+
  40. //        MS Windows 3.X+
  41. //        OS/2 2.X+
  42. //        OS/2 2.0 PM
  43. //        SCO UNIX.
  44. //
  45. //    The following compilers are supported:
  46. //        MSC 6.0A
  47. //        MSC/C++ 7.0
  48. //        Borland C++ 3.1 for DOS
  49. //        Borland C++ 1.0 for OS/2 2.X
  50. //        SCO UNIX cc
  51. //
  52. //----------------------------------------------------------------------------
  53. #include <base.h>
  54.  
  55.  
  56. //----------------------------------------------------------------------------
  57. //    Miscellaneous constants
  58. //----------------------------------------------------------------------------
  59. #define MAX_PHYSICAL_FILES              (8)             // Maximum opened physical files
  60. #define MAX_PHYSICAL_NAME        (80)        // Maximum length of physical file
  61. #define MAX_PHYSICAL_APP_ID    (4)        // Maximum length of physical file
  62.                                                     //  internal name
  63. #define MAX_LOGICAL_FILES        (32)        // Maximum opened logical files
  64. #define MAX_LOGICAL_NAME        (32)        // Maximum length of logical file name
  65.                                                     // Maximum name length "physical~logical"
  66. #define MAX_DIO_NAME                (MAX_PHYSICAL_NAME+MAX_LOGICAL_NAME+1)
  67.  
  68. #define MAX_HEADER_USER            (128)        // User area size (header)
  69. #define MAX_DATA_USER            (64)        // User area size    (data)
  70.  
  71. #define MAX_BLOCK_SIZE            (8 _K)
  72.  
  73. typedef int HPF;                                // hpf, Physical file handle
  74. BASETYPE(HPF);
  75.  
  76. typedef int HLF;                                // hlf, Logical file handle
  77. BASETYPE(HLF);
  78.  
  79. enum DATADIR_TYPE                                // Data file types
  80.     {
  81.     DFT_RANDOM = 0,                            // Random access data -- default
  82.     DFT_DELETED,                                // File has been deleted
  83.     DFT_BLOCK,                                    // Generic blocked data
  84.     DFT_ISAM_DATA,                                // ISAM blocked data
  85.     DFT_ISAM0,                                    // ISAM index - level 0
  86.     DFT_ISAM1,                                    // ISAM index - level 1
  87.     DFT_ISAM2,                                    // ISAM index - level 2
  88.     DFT_ISAM3,                                    // ISAM index - level 3
  89.     DFT_ISAM4,                                    // ISAM index - level 4
  90.     DFT_ISAM5,                                    // ISAM index - level 5
  91.     DFT_ISAM6,                                    // ISAM index - level 6
  92.     DFT_ISAM7,                                    // ISAM index - level 7
  93.     DFT_ISAM8,                                    // ISAM index - level 8
  94.     DFT_ISAM9,                                    // ISAM index - level 9
  95.     DFT_ISAMA,                                    // ISAM index - level 10
  96.     DFT_ISAMB,                                    // ISAM index - level 11
  97.     DFT_ISAMC,                                    // ISAM index - level 12
  98.     DFT_ISAMD,                                    // ISAM index - level 13
  99.     DFT_ISAME,                                    // ISAM index - level 14
  100.     DFT_ISAMF,                                    // ISAM index - level 15
  101.     DFT_ISAM_RECNO,                            // ISAM record number index
  102.     DFT_MAX,
  103.     };
  104.  
  105. //
  106. //    This is a pointer to a function used by the isam indexing routine.
  107. //    This function is passed a pointer to the current block,
  108. //     the size of the current block, a pointer to a buffer
  109. //     to place a key into, and a pointer to a variable to place
  110. //     the size of the key into.
  111. //    This function should generate a key for the first record in the block
  112. //     and place it in the buffer. The size of the key should be placed in the
  113. //     variable which is provided.
  114. //    Function should return TRUE if successful.
  115. //    Key size is limited to ISAM_KEY_LEN bytes in length.
  116. //    This routine is called an extra time at initialization and termination.
  117. //    The block pointer is null at these times. The block size is 0 at start up
  118. //    and 1 at termination.
  119. //
  120. #define ISAM_MAX_LEVEL        (16)            // Maximum isam levels
  121. #define ISAM_KEY_LEN            (256)            // Maximum index key length
  122. #define ISAM_START            (-1)            // Start record code
  123. #define ISAM_END                (-2)            // End record code
  124. typedef struct DI_INDEX
  125. {
  126.     LONG lBlock;                                // Block #, 0..n-1 or special
  127.     PBYTE pbBlock;                                // Pointer to block
  128.     SIZET cbBlock;                                // Size of block in bytes
  129.     PBYTE pbKey;                                // Pointer to key buffer
  130.     SIZET cbKey;                                // Size of key (set by user)
  131. } DI_INDEX;
  132. BASETYPE(DI_INDEX);
  133. typedef BOOL (FN_E *PFNINDEX)(PDI_INDEX);
  134.  
  135. //
  136. //    Macro to convert a physical file handle in a logical file name.
  137. //
  138. #define HPF2PCSZ(x)            ((PCSZ)US2P(x))
  139.  
  140.  
  141. //
  142. //    This is the data structure written to the user data area of
  143. //    a logical file by the file compressor.
  144. //
  145. typedef struct _DA_COMPRESS_USER            // Structure written by compressor
  146. {                                                      //  into user data area
  147.     LONG lRecs;                                    // Total compressed records
  148.     LONG lBytes;                                // Total compressed bytes
  149.     LONG lSlack;                                // Slack bytes
  150.     LONG lBlocks;                                // Total compressed blocks
  151. } DA_COMPRESS_USER;
  152. BASETYPE(DA_COMPRESS_USER);
  153.  
  154. //
  155. //    This is the record ID structure. It is equivalent to 
  156. //    2 ushorts stored in a long.
  157. //
  158. typedef struct RECID
  159. {
  160.     LONG lBlock;
  161.     USHORT usOffset;
  162. } RECID;
  163. BASETYPE(RECID);
  164.  
  165.  
  166. typedef struct DIOTYPE
  167. {
  168.     USHORT usType;
  169.     PSZ pszShort;
  170.     PSZ pszLong;
  171. } DIOTYPE;
  172. extern DIOTYPE adiotype[];
  173.  
  174. //----------------------------------------------------------------------------
  175. //    Prototypes
  176. //----------------------------------------------------------------------------
  177. #if COMPILE_CPP
  178. extern "C"
  179.     {
  180. #endif
  181.  
  182.  
  183. //
  184. //    diappend.c
  185. //
  186. BOOL FN_E DioAppend(PCSZ, PCSZ, USHORT, USHORT, PHF, PBOOL);
  187. BOOL FN_E DioAppendClose(BOOL, BOOL);
  188. BOOL FN_E DioAppendFile(PCSZ, PCSZ, USHORT, USHORT, PCSZ);
  189.  
  190.  
  191. //
  192. //    dicache.c
  193. //
  194. BOOL FN_E DioCacheRelease(HLF);
  195. BOOL FN_E DioCacheSet(HLF, SIZET);
  196.  
  197.  
  198. //
  199. //    dichk.c
  200. //
  201. BOOL FN_E DioCheck(PCSZ);
  202.  
  203.  
  204. //
  205. //    diclose.c
  206. //
  207. BOOL FN_E DioCloseAll(void);
  208. BOOL FN_E DioCloseLogical(HLF);
  209. BOOL FN_E DioClosePhysical(HPF);
  210. BOOL FN_E DioRelease(void);
  211.  
  212.  
  213. //
  214. //    dicopy.c
  215. //
  216. BOOL FN_E DioCopy(PCSZ, PCSZ, PCSZ, PCSZ, USHORT);
  217.  
  218.  
  219. //
  220. //    dicrc.c
  221. //
  222. BOOL FN_E DioCrc(PCSZ, PCSZ, USHORT, PCRC);
  223.  
  224.  
  225. //
  226. //    dicreate.c
  227. //
  228. BOOL FN_E DioCreate(PCSZ, PCSZ, PCSZ, USHORT);
  229.  
  230.  
  231. //
  232. //    didata.c
  233. //
  234. BOOL FN_E DioSetDataPath(PCSZ);
  235.  
  236.  
  237. //
  238. //    didelete.c
  239. //
  240. BOOL FN_E DioDelete(PCSZ, PCSZ, USHORT);
  241.  
  242.  
  243. //
  244. //    diextrac.c
  245. //
  246. BOOL FN_E DioExtract(HLF, PCSZ);
  247. BOOL FN_E DioExtractFile(PCSZ, PCSZ, USHORT, PCSZ);
  248.  
  249.  
  250. //
  251. //    diflush.c
  252. //
  253. BOOL FN_E DioFlush(void);
  254.  
  255.  
  256. //
  257. //    diindex.c
  258. //
  259. BOOL FN_E DioIndex(PCSZ, PCSZ, PFNINDEX, USHORT);
  260.  
  261.  
  262. //
  263. //    diinfo.c
  264. //
  265. BOOL FN_E DioGetBlocks(HLF, PLONG);
  266. BOOL FN_E DioGetBlockSize(HLF, PUSHORT);
  267. BOOL FN_E DioGetFlags(HLF, PFLAG32);
  268. BOOL FN_E DioGetRecords(HLF, PLONG);
  269. BOOL FN_E DioGetSize(HLF, PFPOS);
  270. BOOL FN_E DioGetUser(HLF, PBYTE, SIZET);
  271. BOOL FN_E DioGetVersion(HLF, PUSHORT);
  272. BOOL FN_E DioHeaderGetFlags(HPF, PFLAG32);
  273. BOOL FN_E DioHeaderGetUser(HPF, PBYTE, SIZET);
  274. BOOL FN_E DioHeaderGetVersion(HPF, PUSHORT);
  275. BOOL FN_E DioHeaderSetFlags(HPF, FLAG32);
  276. BOOL FN_E DioHeaderSetUser(HPF, PBYTE, SIZET);
  277. BOOL FN_E DioHeaderSetVersion(HPF, USHORT);
  278. BOOL FN_E DioSetFlags(HLF, FLAG32);
  279. BOOL FN_E DioSetUser(HLF, PBYTE, SIZET);
  280. BOOL FN_E DioSetVersion(HLF, USHORT);
  281.  
  282.  
  283.  
  284. //
  285. //    dimisc.c
  286. //
  287. BOOL FN_E DioIsDataFile(PCSZ, PCSZ);
  288. BOOL FN_E DioIsEof(HLF);
  289. BOOL FN_E DioIsError(HLF);
  290. BOOL FN_E DioIsLogicalFile(PCSZ, USHORT);
  291. BOOL FN_E DioIsValid(HLF);
  292.  
  293.  
  294. //
  295. //    diopen.c
  296. //
  297. BOOL FN_E DioOpenAllPhysical(PCSZ, BOOL);
  298. BOOL FN_E DioOpenIndex(PCSZ, PHLF);
  299. BOOL FN_E DioOpenLogical(PCSZ, PHLF, USHORT);
  300. BOOL FN_E DioOpenPhysical(PCSZ, PHPF, BOOL);
  301.  
  302.  
  303. //
  304. //    diread.c
  305. //
  306. BOOL FN_E DioRead(HLF, PBYTE, SIZET, PSIZET);
  307. BOOL FN_E DioReadBlock(HLF, PBYTE, PBYTE _FAR_ *, PLONG);
  308. BOOL FN_E DioReadFirst(HLF, PBYTE, SIZET, PBYTE, PBYTE _FAR_ *, PLONG);
  309. BOOL FN_E DioReadIndex(HLF, PBYTE, SIZET, PLONG);
  310.  
  311.  
  312. //
  313. //    direcno.c
  314. //
  315. BOOL FN_E DioOpenRecNo(PCSZ, PHLF);
  316. BOOL FN_E DioRecNo2RecId(HLF, LONG, PRECID);
  317. BOOL FN_E DioRecId2RecNo(HLF, PLONG, PRECID);
  318.  
  319.  
  320. //
  321. //    diseek.c
  322. //
  323. BOOL FN_E DioSeek(HLF, FPOS);
  324. BOOL FN_E DioSeekBlock(HLF, LONG);
  325.  
  326.  
  327. //
  328. //    dishow.c
  329. //
  330. BOOL FN_E DioShow(PCSZ, BOOL);
  331.  
  332.  
  333. //
  334. //    diupdate.c
  335. //
  336. BOOL FN_E DioUpdate(PCSZ, PCSZ, USHORT, PCSZ);
  337.  
  338.  
  339. //
  340. //    diwrite.c
  341. //
  342. BOOL FN_E DioWrite(HLF, PBYTE, SIZET, PSIZET);
  343. BOOL FN_E DioWriteBlock(HLF, PBYTE);
  344. BOOL FN_E DioWriteUpdate(HLF);
  345.  
  346.  
  347. #if COMPILE_CPP
  348.     }
  349. #endif
  350. //----------------------------------------------------------------------------
  351. //------------------------------- End of File --------------------------------
  352. //----------------------------------------------------------------------------
  353. #endif                                             // _DIO_H_
  354.